package com.witframework.dynoengine.tool.jspc;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;

public class NewLoader extends ClassLoader
{
  private String baseDir;

  public NewLoader(String paramString)
  {
    this.baseDir = paramString;
  }

  public void setDir(String paramString)
  {
    this.baseDir = paramString;
  }

  public String getDir()
  {
    return this.baseDir;
  }

  public synchronized Class loadClass(String paramString, boolean paramBoolean)
    throws ClassNotFoundException
  {
    Class localClass = loadClassFromFile(getDir(), paramString);
    if (localClass == null) {
      return Class.forName(paramString);
    }
    return localClass;
  }

  public synchronized Class loadClass(String paramString)
    throws ClassNotFoundException
  {
    return loadClass(paramString, true);
  }

  private Class loadClassFromFile(String paramString1, String paramString2)
  {
    String str = paramString1 + File.separatorChar + paramString2.replace('.', File.separatorChar) + ".class";

    Class localClass = null;
    try
    {
      FileInputStream localFileInputStream = new FileInputStream(str);
      BufferedInputStream localBufferedInputStream = new BufferedInputStream(localFileInputStream);
      ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();

      int i = localBufferedInputStream.read();
      while (i != -1)
      {
        localByteArrayOutputStream.write(i);
        i = localBufferedInputStream.read();
      }
      localFileInputStream.close();
      byte[] arrayOfByte = localByteArrayOutputStream.toByteArray();
      localClass = super.defineClass(paramString2, arrayOfByte, 0, arrayOfByte.length);
      localByteArrayOutputStream.close();
    } catch (Exception localException) {
      return null;
    }
    if (localClass != null) super.resolveClass(localClass);

    return localClass;
  }
}